package fm.last.api
{
    import flash.net.URLRequestMethod;
    import flash.net.URLVariables;
    
    import fm.last.Agent;
    import fm.last.RestAPI;
    
    final public class AlbumAPI extends RestAPI
    {
        // those in comment are not implemented yet
        public static const ALBUM_ADD_TAGS:String   = "album.addTags";
        public static const ALBUM_GET_INFO:String   = "album.getInfo";
        public static const ALBUM_GET_TAGS:String   = "album.getTags"; 
        public static const ALBUM_REMOVE_TAG:String = "album.removeTag";
        public static const ALBUM_SEARCH:String     = "album.search";
        
        public function AlbumAPI(agent:Agent)
        {
            super(agent);
        }

        /* ********************************************************************/
        
        /** album.addTags */
        public function addTags(onComplete:Function, 
                                onError:Function,
                                artist:String,
                                album:String,
                                tags:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = AlbumAPI.ALBUM_ADD_TAGS;
            urlVars["artist"] = artist;
            urlVars["album"]  = album;
            urlVars["tags"]   = tags;
            requestAPI(URLRequestMethod.POST, urlVars, true, onComplete, onError);        
        }  
        

        /** album.getInfo */
        public function getInfo(onComplete:Function, 
                                onError:Function,                                
                                artist:String,
                                album:String,
                                mbid:String,               
                                lang:String=null):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = AlbumAPI.ALBUM_GET_INFO;            
            if (artist!=null) urlVars["artist"] = artist;
            if (album!=null)  urlVars["album"]  = album;
            if (mbid!=null)   urlVars["mbid"]   = mbid;
            if (lang!=null)   urlVars["lang"]   = lang;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        
        
        /** album.getTags */
        public function getTags(onComplete:Function, 
                                onError:Function,
                                artist:String,
                                album:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = AlbumAPI.ALBUM_GET_TAGS;
            urlVars["artist"] = artist;
            urlVars["album"]  = album;
            requestAPI(URLRequestMethod.GET, urlVars, true, onComplete, onError);        
        } 
        
        /** album.removeTag */
        public function removeTag(onComplete:Function, 
                                onError:Function,
                                artist:String,
                                album:String,
                                tag:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = AlbumAPI.ALBUM_REMOVE_TAG;
            urlVars["artist"] = artist;
            urlVars["album"]  = album;
            urlVars["tag"]    = tag;
            requestAPI(URLRequestMethod.POST, urlVars, true, onComplete, onError);        
        }  
        

        /** album.search */
        public function search(onComplete:Function, 
                                onError:Function,
                                album:String,                                
                                limit:int=-1,
                                page:int=-1):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = AlbumAPI.ALBUM_SEARCH;
            urlVars["album"]  = album;
            if (limit>0) urlVars["limit"]  = limit;
            if (page>0)  urlVars["page"]   = page;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
    }
}